package orderOpe;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SaleListServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		perform(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		perform(req, resp);
	}

	private void perform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		// 値の取得＆設定
		String customer_code= req.getParameter("code");		
		String start_date = req.getParameter("start_date");
		String last_date = req.getParameter("last_date");
		StringBuffer msg = new StringBuffer();
		
//		int start = Integer.parseInt(start_date);
//		int last = Integer.parseInt(last_date);
		
		boolean start_is_low = (start_date.compareTo(last_date) <= 0);
		
		if(start_is_low || (start_date == null && last_date==null)){

		}
		
		else if(start_date ==null || last_date ==null){
			msg.append("どちらかの日付が選択されていません。。\n");
		}
		
		if(msg.length() ==0){
			if(start_is_low || (start_date == null && last_date==null)){
				req.setAttribute("customer_code", customer_code);
				req.setAttribute("start_date", start_date);
				req.setAttribute("last_date", last_date);
			}
			else if(!start_is_low){
				req.setAttribute("customer_code", customer_code);
				req.setAttribute("last_date", start_date);
				req.setAttribute("start_date", last_date);
			}


			getServletConfig().getServletContext().
			getRequestDispatcher("/operator/saleList.jsp" ).
			forward( req, resp );
		}
		else{
			req.setAttribute("msg", msg);
			getServletConfig().getServletContext().
			getRequestDispatcher("/operator/jisseki.jsp" ).
			forward( req, resp );
		}
	}
}
